/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package locusts.lib.geom;

import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author hamish
 */
public class Alien implements Shape, Cloneable {

    private final GeneralPath path;

    public Alien(double x, double y, double w, double h) {
        path = createAlien(x, y, w, h);
    }

    public Alien(double x, double y, double size) {
        this(x, y, size, size);
    }

    protected Alien(Alien that) {
        this.path = (GeneralPath) that.path.clone();
    }

    public static GeneralPath createAlien(double x, double y, double w,
            double h) {
        final GeneralPath p = new GeneralPath();
        final double x0 = x - w / 2d;
        final double x1 = x - w / 6d;
        final double x2 = x - w / 10d;
        final double x3 = x + w / 10d;
        final double x4 = x + w / 6d;
        final double x5 = x + w / 2d;
        final double y3 = y - h / 2d;
        final double y2 = y - h / 6d;
        final double y1 = y + h / 6d;
        final double y0 = y + h / 2d;

        p.moveTo((float) x0, (float) y1);
        p.lineTo((float) x1, (float) y2);
        p.lineTo((float) x2, (float) y3);
        p.lineTo((float) x3, (float) y3);
        p.lineTo((float) x4, (float) y2);
        p.lineTo((float) x5, (float) y1);
        p.lineTo((float) x4, (float) y0);
        p.lineTo((float) x2, (float) y0);
        p.closePath();
//        p.moveTo((double) x0, (double) y1);
//        p.lineTo((double) x5, (double) y1);
//        p.moveTo((double) x2, (double) y2);
//        p.lineTo((double) x4, (double) y2);

        return p;
    }

    public Rectangle getBounds() {
        return path.getBounds();
    }

    public Rectangle2D getBounds2D() {
        return path.getBounds2D();
    }

    public boolean contains(double x, double y) {
        return path.contains(x, y);
    }

    public boolean contains(Point2D p) {
        return path.contains(p);
    }

    public boolean intersects(double x, double y, double w, double h) {
        return path.intersects(x, y, w, h);
    }

    public boolean intersects(Rectangle2D r) {
        return path.intersects(r);
    }

    public boolean contains(double x, double y, double w, double h) {
        return path.contains(x, y, w, h);
    }

    public boolean contains(Rectangle2D r) {
        return path.contains(r);
    }

    public PathIterator getPathIterator(AffineTransform at) {
        return path.getPathIterator(at);
    }

    public PathIterator getPathIterator(AffineTransform at, double flatness) {
        return path.getPathIterator(at, flatness);
    }

    @Override
    public Alien clone() {
        return new Alien(this);
    }
}
